package com.sprint.service.impl;

import cn.hutool.core.util.IdUtil;
import com.netflix.discovery.converters.Auto;
import com.sprint.service.ImessageProvider;
import com.sun.corba.se.impl.presentation.rmi.IDLTypesUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

//@EnableBinding 3.0已经过时，使用StreamBridge autowired的方式
@Service
public class ImessageProviderImpl implements ImessageProvider {

    @Autowired
    private final StreamBridge streamBridge;

    public ImessageProviderImpl(StreamBridge streamBridge) {
        this.streamBridge = streamBridge;
    }

    @Override
    public String send() {
        String serial = IdUtil.simpleUUID().toString();
        streamBridge.send("myChannel-out-0", MessageBuilder.withPayload(serial).build());
        System.out.println("发送消息: " + serial);
        return null;

    }
}
